<?php
include_once("_common.php");
@include_once("$g4[path]/lib/mw.builder.lib.php");
include_once("$mw_cash[path]/cybercash.lib.php");

if (!is_numeric($page)) $page = 1;

$mb_id = $member['mb_id'];

$sql_common = " from $mw_cash[membership_log_table] ";
$sql_search = " where mb_id = '$mb_id'  ";
$sql_order = " order by ml_datetime desc ";

$sql = "select count(*) as cnt
        $sql_common
        $sql_search";
$row = sql_fetch($sql);
$total_count = $row[cnt];

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함  */

$sql = "select *
        $sql_common
        $sql_search
        $sql_order
        limit $from_record, $rows ";
$qry = sql_query($sql);

$membership_list = array();

$list = array();
for ($i=0; $row=sql_fetch_array($qry); $i++) {
    $list[$i] = $row;
    $list[$i][num] = $total_count - ($page - 1) * $rows - $i;

    if (!$membership_list[$row[ms_id]]) {
        $tmp = sql_fetch("select ms_name from $mw_cash[membership_table] where ms_id = '$row[ms_id]'");
        $membership_list[$row[ms_id]] = $tmp[ms_name];
    }

    $etc = "&nbsp;";
    $gap = strtotime($row[ml_edate]) - strtotime("+$row[ml_day] day", strtotime($row[ml_sdate]));
    $gap = intval($gap/(60*60*24));
    if ($gap)
        $etc = "{$gap}일 서비스";

    $list[$i][etc] = $etc;

    $is_old = false;
    if ($g4[time_ymdhis] > $list[$i][ml_edate]) $is_old = true;
    $list[$i][is_old] = $is_old;

    /*$extend = '';
    if (!$is_old) {
        $sql = "select * from $mw_cash[membership_item_table] where ms_id = '$row[ms_id]' and mi_day = '$row[ml_day]' and mi_status = '1'";
        $tmp = sql_fetch($sql);
        if ($tmp[mi_cash_extend]) {
            $extend = " $tmp[mi_cash_extend]% 할인";
        }
    }
    $list[$i][extend] = $extend;*/
}

$list_count = count($list);

$write_pages = get_paging($rows, $page, $total_page, "$PHP_SELF?{$qstr}&page=");

$colspan = 5;

$g4[title] = "멤버쉽 이용내역";
include_once("_head.php");
?>
<link rel="stylesheet" href="style.css" type="text/css"/>
<script src="cybercash.js"></script>

<h3 class=title>● <?=$g4[title]?></h3>

<div style="height:20px; margin:10px 0 5px 0;">
    <div style="float:left; color:#888;"> 나의 <?=$mw_cash[cf_cash_name]?> :  <?=number_format($mw_cash[mb_cash])?> <?=$mw_cash[cf_cash_unit]?> </div>
    <div style="float:right; color:#888;"> 전체 <?=number_format($list_count)?> 건 </div>
</div>
<table border=0 cellpadding=0 cellspacing=0 width=100% class=data>
<colgroup width="130"/>
<colgroup width=""/>
<colgroup width="130"/>
<colgroup width="130"/>
<colgroup width="100"/>
<tr>
    <td class="head"> 결제일시 </td>
    <td class="head"> 멤버쉽 </td>
    <td class="head"> 시작일시 </td>
    <td class="head"> 종료일시 </td>
    <td class="head"> 비고  </td>
</tr>

<? for ($i=0; $i<$list_count; $i++) { ?>
<tr <? if ($list[$i][is_old]) echo "class='old'"; ?>>
    <td class="body"> <?=$list[$i][ml_datetime]?> </td>
    <td class="body"> <?=$membership_list[$list[$i][ms_id]]?> <?=$list[$i][ml_day]?>일 </td>
    <td class="body"> <?=$list[$i][ml_sdate]?> </td>
    <td class="body">
        <?=$list[$i][ml_edate]?>
        <? /*if (!$list[$i][is_old]) {?>
            [<a href="#;" onclick="buy_membership('','', <?=$list[$i][ms_id]?>)">연장<?=$list[$i][extend]?></a>]
        <? }*/ ?>
 </td>
    <td class="body">
        <?=$list[$i][etc]?>
    </td>
</tr>
<? } ?>
<? if ($i==0) echo "<tr><td colspan=$colspan class=none>자료가 없습니다.</td></tr>"; ?>
</table>

<div class="paging"><?=$write_pages?></div>

<?php
include_once("_tail.php");
?>
